<html>
<head><meta charset="utf-8"><title>Adding Id&#x27;s to TypeFamily · wg-traits · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/index.html">wg-traits</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Adding.20Id&#x27;s.20to.20TypeFamily.html">Adding Id&#x27;s to TypeFamily</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="181123607"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Adding%20Id%27s%20to%20TypeFamily/near/181123607" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Adding.20Id&#x27;s.20to.20TypeFamily.html#181123607">(Nov 19 2019 at 15:44)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span>  So I'm making an attempt at adding <code>TypeId</code> and such to <code>TypeFamily</code>, with associated types like these:</p>
<div class="codehilite"><pre><span></span>type TypeId: Debug + Clone + Eq + Ord + Hash + Zip&lt;Self&gt; + Fold&lt;Self&gt;;
</pre></div>


<p>First hurdle seems to be this derived <code>Fold</code> impl:</p>
<div class="codehilite"><pre><span></span>impl&lt;TF: TypeFamily, _TTF: TypeFamily&gt; Fold&lt;TF, _TTF&gt; for ProjectionTy&lt;TF&gt; {
    type Result = ProjectionTy&lt;_TTF&gt;;
    fn fold_with(
        &amp;self,
        folder: &amp;mut dyn Folder&lt;TF, _TTF&gt;,
        binders: usize,
    ) -&gt; ::chalk_engine::fallible::Fallible&lt;Self::Result&gt; {
        Ok(ProjectionTy {
            associated_ty_id: self.associated_ty_id.fold_with(folder, binders)?,
            parameters: self.parameters.fold_with(folder, binders)?,
        })
    }
}
</pre></div>


<p>That's failing with this error:</p>
<div class="codehilite"><pre><span></span>error[E0308]: mismatched types
   --&gt; chalk-ir/src/lib.rs:602:63
    |
602 |             associated_ty_id: self.associated_ty_id.fold_with(folder, binders)?,
    |                                                               ^^^^^^ expected type parameter, found a different type parameter
    |
    = note: expected type `&amp;mut dyn fold::Folder&lt;TF, TF&gt;`
               found type `&amp;mut dyn fold::Folder&lt;TF, _TTF&gt;`
    = note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound
    = note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters

error[E0308]: try expression alternatives have incompatible types
   --&gt; chalk-ir/src/lib.rs:602:31
    |
602 |             associated_ty_id: self.associated_ty_id.fold_with(folder, binders)?,
    |                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected family::TypeFamily::TypeId, found fold::Fold::Result
    |
    = note: expected type `&lt;_TTF as family::TypeFamily&gt;::TypeId`
               found type `&lt;&lt;TF as family::TypeFamily&gt;::TypeId as fold::Fold&lt;TF&gt;&gt;::Result`
</pre></div>


<p>I'm getting similar errors in <code>super_fold_ty</code> and other Fold derives if I manually fix this one, so some changes to <code>Fold</code> might be required</p>



<a name="181124545"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Adding%20Id%27s%20to%20TypeFamily/near/181124545" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Adding.20Id&#x27;s.20to.20TypeFamily.html#181124545">(Nov 19 2019 at 15:52)</a>:</h4>
<p>(branch here: <a href="https://github.com/rust-lang/chalk/compare/master...detrumi:tf-associated-ids" target="_blank" title="https://github.com/rust-lang/chalk/compare/master...detrumi:tf-associated-ids">https://github.com/rust-lang/chalk/compare/master...detrumi:tf-associated-ids</a>)</p>



<a name="181125167"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Adding%20Id%27s%20to%20TypeFamily/near/181125167" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Adding.20Id&#x27;s.20to.20TypeFamily.html#181125167">(Nov 19 2019 at 15:57)</a>:</h4>
<p>Oh hmm, maybe the <code>+ Fold&lt;Self&gt;</code> bound on <code>TypeId</code> is just wrong, but I don't know what it should be instead, because otherwise <code>self.associated_ty_id.fold_with(...)</code> doesn't work</p>



<a name="181186730"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Adding%20Id%27s%20to%20TypeFamily/near/181186730" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Adding.20Id&#x27;s.20to.20TypeFamily.html#181186730">(Nov 20 2019 at 08:04)</a>:</h4>
<p>The problem is that types like <code>ProjectionTy</code> implement <code>Fold&lt;TF, _TTF&gt;</code>, but we can't reference the <code>_TTF</code> when specifying the trait bounds in the associated type</p>



<a name="181187049"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Adding%20Id%27s%20to%20TypeFamily/near/181187049" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Adding.20Id&#x27;s.20to.20TypeFamily.html#181187049">(Nov 20 2019 at 08:11)</a>:</h4>
<p>I mean, we could do this in the Fold impls, but that would probably get quite unwieldy:</p>
<div class="codehilite"><pre><span></span>where TF::TypeId: Fold&lt;TF, _TTF, Result = _TTF::TypeId&gt;,
</pre></div>



<a name="181188884"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Adding%20Id%27s%20to%20TypeFamily/near/181188884" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Adding.20Id&#x27;s.20to.20TypeFamily.html#181188884">(Nov 20 2019 at 08:47)</a>:</h4>
<p>It's surprising that it's having trouble with the difference between these two:</p>
<div class="codehilite"><pre><span></span>expected type `&lt;&lt;TF as family::TypeFamily&gt;::TypeId as fold::Fold&lt;TF&gt;&gt;::Result`
   found type `&lt;TF as family::TypeFamily&gt;::TypeId`
</pre></div>



<a name="181674007"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Adding%20Id%27s%20to%20TypeFamily/near/181674007" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Adding.20Id&#x27;s.20to.20TypeFamily.html#181674007">(Nov 22 2019 at 20:25)</a>:</h4>
<p><span class="user-mention" data-user-id="125131">@detrumi</span> the right fix here is to have <code>TypeId&lt;TF&gt;</code></p>



<a name="181674012"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Adding%20Id%27s%20to%20TypeFamily/near/181674012" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Adding.20Id&#x27;s.20to.20TypeFamily.html#181674012">(Nov 22 2019 at 20:25)</a>:</h4>
<p>and have that implement <code>Fold</code></p>



<a name="181674020"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Adding%20Id%27s%20to%20TypeFamily/near/181674020" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Adding.20Id&#x27;s.20to.20TypeFamily.html#181674020">(Nov 22 2019 at 20:25)</a>:</h4>
<p>and then (internally) it wraps a <code>TF::TypeId</code></p>



<a name="181674033"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Adding%20Id%27s%20to%20TypeFamily/near/181674033" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Adding.20Id&#x27;s.20to.20TypeFamily.html#181674033">(Nov 22 2019 at 20:25)</a>:</h4>
<p>much like we have <code>Ty&lt;TF&gt;</code> which wraps a <code>TF::InternedTy</code></p>



<a name="181674093"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Adding%20Id%27s%20to%20TypeFamily/near/181674093" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Adding.20Id&#x27;s.20to.20TypeFamily.html#181674093">(Nov 22 2019 at 20:26)</a>:</h4>
<p>this does however imply that there has to be some kind of "conversion" between type-families for id's</p>



<a name="181674094"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Adding%20Id%27s%20to%20TypeFamily/near/181674094" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Adding.20Id&#x27;s.20to.20TypeFamily.html#181674094">(Nov 22 2019 at 20:26)</a>:</h4>
<p>hmm</p>



<a name="181674108"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Adding%20Id%27s%20to%20TypeFamily/near/181674108" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Adding.20Id&#x27;s.20to.20TypeFamily.html#181674108">(Nov 22 2019 at 20:26)</a>:</h4>
<p>interesting problem!</p>



<a name="181674149"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Adding%20Id%27s%20to%20TypeFamily/near/181674149" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Adding.20Id&#x27;s.20to.20TypeFamily.html#181674149">(Nov 22 2019 at 20:27)</a>:</h4>
<p>it works for types because we have a "canonical" form to convert into / from</p>



<a name="181674201"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Adding%20Id%27s%20to%20TypeFamily/near/181674201" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Adding.20Id&#x27;s.20to.20TypeFamily.html#181674201">(Nov 22 2019 at 20:28)</a>:</h4>
<p>I have to wonder if the "conversion between type families" is worth it</p>



<a name="181674254"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Adding%20Id%27s%20to%20TypeFamily/near/181674254" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Adding.20Id&#x27;s.20to.20TypeFamily.html#181674254">(Nov 22 2019 at 20:28)</a>:</h4>
<p>I do think it's an interesting idea but it does add some complexity</p>



<a name="181674293"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Adding%20Id%27s%20to%20TypeFamily/near/181674293" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Adding.20Id&#x27;s.20to.20TypeFamily.html#181674293">(Nov 22 2019 at 20:28)</a>:</h4>
<p>otherwise I guess we need to add some sort of "canonical id" that is maybe just a fixed number of integers :)</p>



<a name="181674450"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Adding%20Id%27s%20to%20TypeFamily/near/181674450" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Adding.20Id&#x27;s.20to.20TypeFamily.html#181674450">(Nov 22 2019 at 20:31)</a>:</h4>
<p>/me shrugs</p>



<a name="181674451"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Adding%20Id%27s%20to%20TypeFamily/near/181674451" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Adding.20Id&#x27;s.20to.20TypeFamily.html#181674451">(Nov 22 2019 at 20:31)</a>:</h4>
<p>maybe we should just do that for now</p>



<a name="181674460"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Adding%20Id%27s%20to%20TypeFamily/near/181674460" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Adding.20Id&#x27;s.20to.20TypeFamily.html#181674460">(Nov 22 2019 at 20:31)</a>:</h4>
<p>just make "unpack id" convert to a <code>(u64, u64)</code> or something</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>